/*
 * @Author       : ShiJunJie
 * @Date         : 2022-04-18 16:53:59
 * @LastEditors  : ShiJunJie
 * @LastEditTime : 2022-04-19 11:10:08
 * @FilePath     : /src/stores/asyncRouter.ts
 * @Descripttion : 路由vuex(pinia)
 */

import { patDown } from "@/utils/util"
import { StorageSerializers, useStorage } from '@vueuse/core'


export const useRouterStore = defineStore("Router", {
  state: () => {
    const routers = useStorage('USER_ROUTERS', null, undefined, { serializer: StorageSerializers.object })
    return { routers }
  },
  getters: {
  },
  actions: {
    set(data: any) {
      this.routers = useStorage('USER_ROUTERS', data, undefined, { serializer: StorageSerializers.object })
    },
    get() {
      const resData = Object.fromEntries(patDown(this.routers).map((e, i) => [e['name'] || `name_${i}`, { ...e, children: undefined }]))
      console.log('useRouterStore', this.routers, resData, useRoute().matched);
      return resData
    },
  }
})
